<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>天气小助手 - 美化收藏版</title>
    <style>
        :root {
            --primary-color: #4a6fa5;
            --secondary-color: #6b8cae;
            --accent-color: #ff7e5f;
            --light-color: #f8f9fa;
            --dark-color: #343a40;
            --success-color: #28a745;
            --warning-color: #ffc107;
            --danger-color: #dc3545;
            --nav-bg: #2c3e50;
            --nav-active: #3498db;
            --nav-text: #ecf0f1;
            --card-bg: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
            --card-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
        }
        
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        body {
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
            padding: 20px;
            color: var(--dark-color);
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
            background-color: rgba(255, 255, 255, 0.95);
            border-radius: 15px;
            box-shadow: var(--card-shadow);
            overflow: hidden;
        }
        
        header {
            text-align: center;
            padding: 25px 0;
            background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
            color: white;
            border-radius: 10px 10px 0 0;
            position: relative;
            overflow: hidden;
        }
        
        header::after {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" opacity="0.05"><path fill="white" d="M30,30 Q50,10 70,30 T90,50 Q70,70 50,90 T30,70 Q10,50 30,30 Z"/></svg>');
            background-size: 80px;
        }
        
        h1 {
            font-size: 2.5rem;
            margin-bottom: 10px;
            position: relative;
            z-index: 1;
            text-shadow: 0 2px 4px rgba(0,0,0,0.2);
        }
        
        .tagline {
            font-size: 1.2rem;
            opacity: 0.9;
            position: relative;
            z-index: 1;
        }
        
        .nav-container {
            background-color: var(--nav-bg);
            display: flex;
            justify-content: center;
            padding: 0 20px;
            position: relative;
        }
        
        .nav-tabs {
            display: flex;
            max-width: 100%;
            overflow-x: auto;
            scrollbar-width: none;
            -ms-overflow-style: none;
        }
        
        .nav-tabs::-webkit-scrollbar {
            display: none;
        }
        
        .nav-tab {
            padding: 15px 25px;
            cursor: pointer;
            color: var(--nav-text);
            font-weight: 500;
            font-size: 1.1rem;
            white-space: nowrap;
            border-bottom: 3px solid transparent;
            transition: all 0.3s ease;
            position: relative;
        }
        
        .nav-tab.active {
            background-color: rgba(255, 255, 255, 0.1);
            border-bottom-color: var(--nav-active);
            color: white;
        }
        
        .nav-tab:hover:not(.active) {
            background-color: rgba(255, 255, 255, 0.05);
            border-bottom-color: rgba(255, 255, 255, 0.2);
        }
        
        .nav-tab i {
            margin-right: 8px;
        }
        
        .tab-content {
            display: none;
            padding: 25px;
            animation: fadeIn 0.5s;
        }
        
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }
        
        .tab-content.active {
            display: block;
        }
        
        .search-container {
            display: flex;
            margin-bottom: 20px;
            position: relative;
        }
        
        input[type="text"] {
            flex: 1;
            padding: 12px 15px;
            border: 1px solid #ddd;
            border-radius: 8px 0 0 8px;
            font-size: 1rem;
            outline: none;
            transition: all 0.3s;
            box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
        }
        
        input[type="text"]:focus {
            border-color: var(--primary-color);
            box-shadow: 0 0 0 3px rgba(74, 111, 165, 0.2);
        }
        
        button {
            padding: 12px 20px;
            background-color: var(--primary-color);
            color: white;
            border: none;
            border-radius: 0 8px 8px 0;
            cursor: pointer;
            font-size: 1rem;
            transition: all 0.3s;
            box-shadow: 0 2px 5px rgba(0,0,0,0.1);
        }
        
        button:hover {
            background-color: var(--secondary-color);
            transform: translateY(-1px);
            box-shadow: 0 4px 8px rgba(0,0,0,0.15);
        }
        
        button:active {
            transform: translateY(0);
            box-shadow: 0 2px 3px rgba(0,0,0,0.1);
        }
        
        /* 天气卡片样式 */
        .weather-card {
            background: var(--card-bg);
            border-radius: 12px;
            padding: 20px;
            box-shadow: var(--card-shadow);
            transition: all 0.3s ease;
            margin-bottom: 20px;
            border: 1px solid rgba(0, 0, 0, 0.05);
            position: relative;
            overflow: hidden;
        }
        
        .weather-card::before {
            content: "";
            position: absolute;
            top: 0;
            right: 0;
            width: 100px;
            height: 100px;
            background: linear-gradient(45deg, rgba(74, 111, 165, 0.05) 0%, rgba(74, 111, 165, 0.01) 100%);
            border-radius: 0 0 0 100%;
        }
        
        .weather-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 8px 25px rgba(0, 0, 0, 0.12);
        }
        
        .weather-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 15px;
        }
        
        .city-name {
            font-size: 1.5rem;
            font-weight: 600;
            color: var(--primary-color);
        }
        
        .weather-icon {
            font-size: 3.5rem;
            color: var(--primary-color);
            margin-right: 15px;
        }
        
        .weather-main {
            display: flex;
            align-items: center;
            margin-bottom: 15px;
        }
        
        .temperature {
            font-size: 2.5rem;
            font-weight: 700;
            margin-right: 15px;
        }
        
        .weather-description {
            font-size: 1.1rem;
            color: #666;
        }
        
        .weather-details {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
            gap: 15px;
            margin-top: 20px;
        }
        
        .detail-item {
            background: rgba(255, 255, 255, 0.7);
            padding: 10px;
            border-radius: 8px;
            text-align: center;
            box-shadow: 0 2px 5px rgba(0,0,0,0.05);
        }
        
        .detail-label {
            font-size: 0.85rem;
            color: #666;
            margin-bottom: 5px;
        }
        
        .detail-value {
            font-weight: 600;
            font-size: 1.1rem;
        }
        
        /* 收藏页面样式 */
        .favorites-container {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
            gap: 20px;
            margin-top: 20px;
        }
        
        .favorite-card {
            background: var(--card-bg);
            border-radius: 12px;
            padding: 20px;
            box-shadow: var(--card-shadow);
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
            border: 1px solid rgba(0, 0, 0, 0.05);
        }
        
        .favorite-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 8px 25px rgba(0, 0, 0, 0.12);
        }
        
        .favorite-card::before {
            content: "";
            position: absolute;
            top: 0;
            right: 0;
            width: 80px;
            height: 80px;
            background: linear-gradient(45deg, rgba(255, 126, 95, 0.08) 0%, rgba(255, 126, 95, 0.02) 100%);
            border-radius: 0 0 0 100%;
        }
        
        .favorite-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 15px;
        }
        
        .favorite-city {
            font-size: 1.3rem;
            font-weight: 600;
            color: var(--primary-color);
        }
        
        .remove-favorite {
            background: none;
            border: none;
            color: var(--danger-color);
            font-size: 1.2rem;
            cursor: pointer;
            transition: all 0.2s;
            width: 30px;
            height: 30px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 50%;
        }
        
        .remove-favorite:hover {
            background: rgba(220, 53, 69, 0.1);
            transform: scale(1.1);
        }
        
        .favorite-weather {
            display: flex;
            align-items: center;
            margin-bottom: 15px;
        }
        
        .favorite-icon {
            font-size: 2.5rem;
            color: var(--accent-color);
            margin-right: 15px;
        }
        
        .favorite-temp {
            font-size: 1.8rem;
            font-weight: 600;
            margin-right: 15px;
        }
        
        .favorite-condition {
            font-size: 1rem;
            color: #666;
        }
        
        .favorite-details {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 10px;
            margin-top: 15px;
        }
        
        .favorite-detail {
            background: rgba(255, 255, 255, 0.7);
            padding: 8px;
            border-radius: 6px;
            text-align: center;
            box-shadow: 0 1px 3px rgba(0,0,0,0.05);
        }
        
        .favorite-detail-label {
            font-size: 0.8rem;
            color: #666;
        }
        
        .favorite-detail-value {
            font-weight: 600;
            font-size: 0.95rem;
        }
        
        .add-favorite-btn {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            background: rgba(255, 255, 255, 0.5);
            border: 2px dashed #ccc;
            border-radius: 12px;
            padding: 30px;
            cursor: pointer;
            transition: all 0.3s;
            height: 100%;
            min-height: 180px;
        }
        
        .add-favorite-btn:hover {
            background: rgba(255, 255, 255, 0.7);
            border-color: var(--primary-color);
        }
        
        .add-favorite-btn i {
            font-size: 2.5rem;
            color: var(--primary-color);
            margin-bottom: 10px;
        }
        
        .add-favorite-btn span {
            color: var(--primary-color);
            font-weight: 500;
        }
        
        /* 加载状态 */
        .loading {
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 50px;
        }
        
        .spinner {
            width: 40px;
            height: 40px;
            border: 4px solid rgba(0, 0, 0, 0.1);
            border-radius: 50%;
            border-top-color: var(--primary-color);
            animation: spin 1s ease-in-out infinite;
        }
        
        @keyframes spin {
            to {
                transform: rotate(360deg);
            }
        }
        
        /* 空状态 */
        .empty-state {
            text-align: center;
            padding: 40px 20px;
            color: #6c757d;
        }
        
        .empty-state i {
            font-size: 3rem;
            margin-bottom: 15px;
            opacity: 0.5;
        }
        
        .empty-state p {
            font-size: 1.1rem;
        }
        
        /* 响应式设计 */
        @media (max-width: 768px) {
            .favorites-container {
                grid-template-columns: 1fr;
            }
            
            .weather-details, .favorite-details {
                grid-template-columns: repeat(2, 1fr);
            }
            
            .nav-tab {
                padding: 12px 15px;
                font-size: 1rem;
            }
        }
    </style>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
</head>
<body>
    <div class="container">
        <header>
            <h1>天气小助手</h1>
            <p class="tagline">实时天气查询与收藏</p>
        </header>
        
        <div class="nav-container">
            <div class="nav-tabs">
                <div class="nav-tab active" onclick="openTab('weather-tab')">
                    <i class="fas fa-cloud-sun"></i> 天气查询
                </div>
                <div class="nav-tab" onclick="openTab('favorites-tab')">
                    <i class="fas fa-heart"></i> 我的收藏
                </div>
            </div>
        </div>
        
        <div id="weather-tab" class="tab-content active">
            <div class="search-container">
                <input type="text" id="search-input" placeholder="输入城市名称，例如: 上海" onkeypress="handleKeyPress(event)">
                <button onclick="searchWeather()"><i class="fas fa-search"></i> 查询天气</button>
            </div>
            
            <div id="weather-results">
                <div class="empty-state">
                    <i class="fas fa-cloud-sun"></i>
                    <p>输入城市名称查询天气信息</p>
                </div>
            </div>
        </div>
        
        <div id="favorites-tab" class="tab-content">
            <h2><i class="fas fa-heart" style="color: var(--accent-color);"></i> 我的收藏城市</h2>
            <p style="color: #666;">您收藏的城市天气信息将在这里显示</p>
            
            <div class="favorites-container" id="favorites-list">
                <div class="add-favorite-btn" onclick="addCurrentToFavorites()">
                    <i class="fas fa-plus-circle"></i>
                    <span>添加收藏城市</span>
                </div>
            </div>
        </div>
    </div>
    
    <script>
        // 全局变量
        let currentCity = '';
        let currentWeatherData = null;
        let favorites = JSON.parse(localStorage.getItem('favorites')) || [];
        
        // 页面加载时初始化
        document.addEventListener('DOMContentLoaded', function() {
            renderFavorites();
            
            // 尝试加载上次查询的城市
            const lastCity = localStorage.getItem('lastCity');
            if (lastCity) {
                document.getElementById('search-input').value = lastCity;
            }
        });
        
        // 标签页切换
        function openTab(tabId) {
            const tabContents = document.getElementsByClassName('tab-content');
            for (let i = 0; i < tabContents.length; i++) {
                tabContents[i].classList.remove('active');
            }
            
            const tabs = document.getElementsByClassName('nav-tab');
            for (let i = 0; i < tabs.length; i++) {
                tabs[i].classList.remove('active');
            }
            
            document.getElementById(tabId).classList.add('active');
            event.currentTarget.classList.add('active');
        }
        
        // 处理键盘回车事件
        function handleKeyPress(event) {
            if (event.key === 'Enter') {
                searchWeather();
            }
        }
        
        // 搜索天气
        function searchWeather() {
            const city = document.getElementById('search-input').value.trim();
            if (!city) {
                showNotification('请输入城市名称');
                return;
            }
            
            currentCity = city;
            localStorage.setItem('lastCity', city);
            fetchWeather(city);
        }
        
        // 获取天气数据
        async function fetchWeather(city) {
            const weatherResults = document.getElementById('weather-results');
            weatherResults.innerHTML = '<div class="loading"><div class="spinner"></div></div>';
            
            try {
                // 使用CORS代理绕过限制
                const proxyUrl = 'https://api.allorigins.win/raw?url=';
                const apiUrl = `https://api.yyy001.com/api/weather?msg=${encodeURIComponent(city)}`;
                
                const response = await fetch(proxyUrl + encodeURIComponent(apiUrl));
                
                if (!response.ok) {
                    throw new Error('获取天气数据失败: ' + response.statusText);
                }
                
                const data = await response.json();
                
                if (data.code !== 200) {
                    throw new Error(data.msg || '获取天气数据失败');
                }
                
                currentWeatherData = data.data;
                renderWeather();
            } catch (error) {
                console.error('获取天气数据失败:', error);
                weatherResults.innerHTML = `
                    <div class="empty-state">
                        <i class="fas fa-exclamation-triangle"></i>
                        <p>${error.message || '无法获取天气数据，请检查城市名称或稍后再试'}</p>
                    </div>
                `;
                
                // 如果API请求失败，使用模拟数据
                useMockData(city);
            }
        }
        
        // 使用模拟数据
        function useMockData(city) {
            currentWeatherData = {
                moji: {
                    code: 200,
                    data: {
                        city: `中国-${city}-${city}`,
                        forecast: [
                            {
                                date: null,
                                dayWeather: "晴",
                                nightWeather: "晴",
                                temperature: "5~12℃",
                                humidity: 58,
                                windDay: "东风 2级",
                                windNight: "东风 2级",
                                airQuality: "优"
                            },
                            {
                                date: null,
                                dayWeather: "多云",
                                nightWeather: "多云",
                                temperature: "4~14℃",
                                humidity: 70,
                                windDay: "东北风 2级",
                                windNight: "东北风 2级",
                                airQuality: "良"
                            },
                            {
                                date: null,
                                dayWeather: "晴",
                                nightWeather: "晴",
                                temperature: "3~11℃",
                                humidity: 67,
                                windDay: "东北风 3级",
                                windNight: "东北风 2级",
                                airQuality: "良"
                            },
                            {
                                date: null,
                                dayWeather: "多云",
                                nightWeather: "阴",
                                temperature: "6~11℃",
                                humidity: 61,
                                windDay: "东南风 3级",
                                windNight: "东南风 2级",
                                airQuality: "良"
                            },
                            {
                                date: null,
                                dayWeather: "阴",
                                nightWeather: "晴",
                                temperature: "4~11℃",
                                humidity: 73,
                                windDay: "西风 2级",
                                windNight: "西南风 2级",
                                airQuality: "良"
                            }
                        ]
                    }
                }
            };
            renderWeather();
            showNotification('使用模拟数据进行演示');
        }
        
        // 渲染天气数据
        function renderWeather() {
            const weatherResults = document.getElementById('weather-results');
            
            if (!currentWeatherData || !currentWeatherData.moji) {
                weatherResults.innerHTML = `
                    <div class="empty-state">
                        <i class="fas fa-exclamation-triangle"></i>
                        <p>暂无天气数据</p>
                    </div>
                `;
                return;
            }
            
            const weatherData = currentWeatherData.moji.data;
            const current = weatherData.forecast[0];
            
            // 天气图标映射
            const iconMap = {
                '晴': 'fas fa-sun',
                '多云': 'fas fa-cloud',
                '阴': 'fas fa-cloud',
                '雨': 'fas fa-cloud-rain',
                '小雨': 'fas fa-cloud-rain',
                '中雨': 'fas fa-cloud-showers-heavy',
                '大雨': 'fas fa-cloud-showers-heavy',
                '暴雨': 'fas fa-poo-storm',
                '雪': 'fas fa-snowflake',
                '小雪': 'fas fa-snowflake',
                '中雪': 'fas fa-snowflake',
                '大雪': 'fas fa-snowflake',
                '雾': 'fas fa-smog',
                '霾': 'fas fa-smog'
            };
            
            const currentIcon = iconMap[current.dayWeather] || 'fas fa-cloud';
            const cityName = weatherData.city.split('-')[1] || currentCity;
            
            let weatherHTML = `
                <div class="weather-card">
                    <div class="weather-header">
                        <h2 class="city-name">${cityName}</h2>
                        <i class="weather-icon ${currentIcon}"></i>
                    </div>
                    
                    <div class="weather-main">
                        <div class="temperature">${current.temperature}</div>
                        <div>
                            <div class="weather-description">${current.dayWeather}</div>
                            <div style="font-size:0.9rem;color:#666;">${current.windDay}</div>
                        </div>
                    </div>
                    
                    <div class="weather-details">
                        <div class="detail-item">
                            <div class="detail-label">湿度</div>
                            <div class="detail-value">${current.humidity}%</div>
                        </div>
                        <div class="detail-item">
                            <div class="detail-label">空气质量</div>
                            <div class="detail-value">${current.airQuality}</div>
                        </div>
                        <div class="detail-item">
                            <div class="detail-label">夜间天气</div>
                            <div class="detail-value">${current.nightWeather}</div>
                        </div>
                        <div class="detail-item">
                            <div class="detail-label">夜间风力</div>
                            <div class="detail-value">${current.windNight}</div>
                        </div>
                    </div>
                    
                    <button onclick="addCurrentToFavorites()" style="margin-top:20px;width:100%;padding:10px;background:var(--accent-color);border:none;border-radius:8px;color:white;font-weight:600;cursor:pointer;transition:all 0.3s;">
                        <i class="fas fa-heart"></i> 收藏该城市
                    </button>
                </div>
                
                <h3 style="margin:25px 0 15px;color:var(--primary-color);">未来5天预报</h3>
                <div style="display:grid;grid-template-columns:repeat(auto-fill, minmax(150px, 1fr));gap:15px;">
            `;
            
            // 预报数据
            weatherData.forecast.slice(0, 5).forEach((day, index) => {
                const dayNames = ['今天', '明天', '后天', '大后天', '大大后天'];
                const dayName = dayNames[index] || `第${index+1}天`;
                const dayIcon = iconMap[day.dayWeather] || 'fas fa-cloud';
                
                weatherHTML += `
                    <div style="background:white;border-radius:10px;padding:15px;box-shadow:0 2px 8px rgba(0,0,0,0.05);">
                        <div style="font-weight:600;margin-bottom:10px;color:var(--primary-color);">${dayName}</div>
                        <div style="display:flex;align-items:center;margin-bottom:8px;">
                            <i class="${dayIcon}" style="font-size:1.5rem;margin-right:10px;color:var(--accent-color);"></i>
                            <span>${day.dayWeather}</span>
                        </div>
                        <div style="font-size:0.9rem;color:#666;">${day.temperature}</div>
                        <div style="font-size:0.8rem;margin-top:5px;color:#888;">${day.airQuality}</div>
                    </div>
                `;
            });
            
            weatherHTML += `</div>`;
            weatherResults.innerHTML = weatherHTML;
        }
        
        // 添加当前城市到收藏
        function addCurrentToFavorites() {
            if (!currentCity) {
                showNotification('请先查询一个城市');
                return;
            }
            
            if (favorites.some(fav => fav.city === currentCity)) {
                showNotification(`${currentCity} 已经在您的收藏列表中`);
                return;
            }
            
            if (!currentWeatherData || !currentWeatherData.moji) {
                showNotification('无法获取当前天气数据');
                return;
            }
            
            const weatherData = currentWeatherData.moji.data;
            const current = weatherData.forecast[0];
            
            favorites.push({
                city: currentCity,
                temperature: current.temperature,
                weather: current.dayWeather,
                humidity: current.humidity,
                wind: current.windDay,
                airQuality: current.airQuality,
                timestamp: Date.now()
            });
            
            saveFavorites();
            renderFavorites();
            showNotification(`${currentCity} 已添加到收藏`);
        }
        
        // 从收藏移除
        function removeFavorite(city, event) {
            event.stopPropagation();
            favorites = favorites.filter(fav => fav.city !== city);
            saveFavorites();
            renderFavorites();
            showNotification(`${city} 已从收藏移除`);
        }
        
        // 保存收藏到本地存储
        function saveFavorites() {
            localStorage.setItem('favorites', JSON.stringify(favorites));
        }
        
        // 渲染收藏列表
        function renderFavorites() {
            const favoritesList = document.getElementById('favorites-list');
            
            // 保留添加按钮
            let favoritesHTML = `
                <div class="add-favorite-btn" onclick="addCurrentToFavorites()">
                    <i class="fas fa-plus-circle"></i>
                    <span>添加收藏城市</span>
                </div>
            `;
            
            if (favorites.length === 0) {
                favoritesList.innerHTML = favoritesHTML + `
                    <div style="grid-column:1/-1;text-align:center;padding:40px 20px;color:#6c757d;">
                        <i class="fas fa-heart" style="font-size:2.5rem;opacity:0.3;margin-bottom:15px;"></i>
                        <p>暂无收藏城市，点击上方按钮添加</p>
                    </div>
                `;
                return;
            }
            
            // 天气图标映射
            const iconMap = {
                '晴': 'fas fa-sun',
                '多云': 'fas fa-cloud',
                '阴': 'fas fa-cloud',
                '雨': 'fas fa-cloud-rain',
                '小雨': 'fas fa-cloud-rain',
                '中雨': 'fas fa-cloud-showers-heavy',
                '大雨': 'fas fa-cloud-showers-heavy',
                '暴雨': 'fas fa-poo-storm',
                '雪': 'fas fa-snowflake',
                '小雪': 'fas fa-snowflake',
                '中雪': 'fas fa-snowflake',
                '大雪': 'fas fa-snowflake',
                '雾': 'fas fa-smog',
                '霾': 'fas fa-smog'
            };
            
            // 按添加时间排序，最新的在前面
            const sortedFavorites = [...favorites].sort((a, b) => b.timestamp - a.timestamp);
            
            sortedFavorites.forEach(fav => {
                const weatherIcon = iconMap[fav.weather] || 'fas fa-cloud';
                
                favoritesHTML += `
                    <div class="favorite-card" onclick="searchFavorite('${fav.city}')">
                        <div class="favorite-header">
                            <h3 class="favorite-city">${fav.city}</h3>
                            <button class="remove-favorite" onclick="removeFavorite('${fav.city}', event)">
                                <i class="fas fa-times"></i>
                            </button>
                        </div>
                        
                        <div class="favorite-weather">
                            <i class="favorite-icon ${weatherIcon}"></i>
                            <div class="favorite-temp">${fav.temperature}</div>
                            <div class="favorite-condition">${fav.weather}</div>
                        </div>
                        
                        <div class="favorite-details">
                            <div class="favorite-detail">
                                <div class="favorite-detail-label">湿度</div>
                                <div class="favorite-detail-value">${fav.humidity}%</div>
                            </div>
                            <div class="favorite-detail">
                                <div class="favorite-detail-label">风力</div>
                                <div class="favorite-detail-value">${fav.wind}</div>
                            </div>
                            <div class="favorite-detail">
                                <div class="favorite-detail-label">空气质量</div>
                                <div class="favorite-detail-value">${fav.airQuality}</div>
                            </div>
                            <div class="favorite-detail">
                                <div class="favorite-detail-label">更新时间</div>
                                <div class="favorite-detail-value">${formatTime(fav.timestamp)}</div>
                            </div>
                        </div>
                    </div>
                `;
            });
            
            favoritesList.innerHTML = favoritesHTML;
        }
        
        // 格式化时间
        function formatTime(timestamp) {
            const date = new Date(timestamp);
            return `${date.getHours()}:${date.getMinutes().toString().padStart(2, '0')}`;
        }
        
        // 搜索收藏的城市
        function searchFavorite(city) {
            document.getElementById('search-input').value = city;
            currentCity = city;
            fetchWeather(city);
            openTab('weather-tab');
        }
        
        // 显示通知
        function showNotification(message) {
            const notification = document.createElement('div');
            notification.className = 'notification';
            notification.innerHTML = `<i class="fas fa-check-circle"></i> ${message}`;
            document.body.appendChild(notification);
            
            setTimeout(() => {
                notification.remove();
            }, 3000);
        }
    </script>
</body>
</html>